<TITLE>BGI Documentation for 
setrgbpalette
</TITLE>
<H2>
setrgbpalette
</H2>
<HR>
<DL>


<DT><B>Syntax</B><DD>
<PRE>
#include &lt;graphics.h&gt;
void setrgbpalette(int colornum, int red, int green, int blue);
</PRE>



<DT><B>Description</B><DD>
setrgbpalette can be used with the IBM 8514 and VGA drivers.
<P>
colornum defines the palette entry to be loaded, while red, green, and blue define the component colors of the palette entry.
<P>
For the IBM 8514 display (and the VGA in 256K color mode), colornum is in the range 0 to 255. For the remaining modes of the VGA, colornum is in the range 0 to 15. Only the lower byte of red, green, or blue is used, and out of each byte, only the 6 most significant bits are loaded in the palette.
<P>
For compatibility with other IBM graphics adapters, the BGI driver defines the first 16 palette entries of the IBM 8514 to the default colors of the EGA/VGA. These values can be used as is, or they can be changed using setrgbpalette.


<P><DT><B>Return Value</B><DD>
None.

<P><DT><B>Windows Notes <IMG SRC="win.gif" ALT="[WIN]"></B><DD>
The <A HREF="../../bgi/README.html">winbgim</A> version allows the
the colornum to be a palette index from 0 to 15.
The call
<PRE>
    setrgbpalette(colornum, r, g, b);
</PRE>
is similar to
<PRE>
    setpalette(colornum, COLOR(r,g,b) );
</PRE>
The difference is that setrgbpalette will use only the six most
significant
bits of the least significant byte of r, g and b. However, COLOR(r,g,b) uses
the entire least significant byte of r, g and b.
color
argument to be an ordinary BGI color (from 0 to 15) or an
<A HREF="wincolor.html">RGB color</A>.
<P>
In the windows version, changing the palette effects only future
drawing.
Currently drawn pixels do not change their color when the palette
changes
(no "palette animation").

<P><DT><B>See also</B>
<DD><A HREF="setpalette.html"> setpalette </A>


<P><DT><B>Example</B><DD>
<PRE>
/* setrgbpalette example */ 

#include &lt;graphics.h&gt;
#include &lt;stdlib.h&gt;
#include &lt;stdio.h&gt;
#include &lt;conio.h&gt;

int main(void)
{
   /* select driver and mode that supports use of setrgbpalette */
   int gdriver = VGA, gmode = VGAHI, errorcode;
   struct palettetype pal;
   int i, ht, y, xmax;

   /* initialize graphics and local variables */
   initgraph(&gdriver, &gmode, "");

   /* read result of initialization */
   errorcode = graphresult();
   if (errorcode != grOk) {  /* an error occurred */

      printf("Graphics error: %s\n", grapherrormsg(errorcode));
      printf("Press any key to halt:");
      getch();
      exit(1);               /* terminate with an error code */
   }

   /* grab a copy of the palette */
   getpalette(&pal);


   /* create gray scale */
   for (i=0; i&lt;pal.size; i++)
      setrgbpalette(pal.colors[i], i*4, i*4, i*4);

   /* display the gray scale */
   ht = getmaxy() / 16;
   xmax = getmaxx();
   y = 0;
   for (i=0; i&lt;pal.size; i++) {

      setfillstyle(SOLID_FILL, i);
      bar(0, y, xmax, y+ht);
      y += ht;
   }

   /* clean up */
   getch();
   closegraph();
   return 0;
}
</PRE>


</DL>
<HR>
<A HREF="index.html">Back to index</A>
